package org.leon.controller;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.leon.bean.UserValidator;
import org.leon.bean.UserValidator2;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.validation.Valid;


/**
 * Created by Administrator on 2017/4/25.
 * 测试国际化
 */
@Controller
@RequestMapping(value = "/validate2")
public class UserValidatorController2 {

    private static final Log logger = LogFactory.getLog(UserValidatorController2.class);

    @RequestMapping(value = "/registerForm")
        public String loginForm(Model model){

        UserValidator2 user = new UserValidator2();
        model.addAttribute("user", user);

        return "validate/registerFormMessage";
    }


    /**
     * 测试国际化资源
     * @param user
     * @param result
     * @param model
     * @return
     */
    @RequestMapping(value = "/login2")
    public String login2(@Valid @ModelAttribute("user") UserValidator2 user,
                        BindingResult result, // 必须跟在@Valid后面
                        Model model){
        logger.info(user);

        if(result.hasErrors()){
            return "validate/registerFormMessage";
        }
        model.addAttribute("user", user);


        return "validate/success";

    }
}
